Skip to content

report friendly error when cli fails to find shops to display#3702

Open
sealocal wants to merge 1 commit intoShopify:mainfrom
sealocal:fix-for-cli-link-command
Open

report friendly error when cli fails to find shops to display#3702
sealocal wants to merge 1 commit intoShopify:mainfrom
sealocal:fix-for-cli-link-command

Conversation

@sealocal
Copy link
Copy Markdown

WHY are these changes introduced?

Fixes #2772 and #1463

The SelectPrompt component is being called and erroring out with 0 choices passed to it.

This approach avoids modifying the re-used SelectPrompt, isolating the change to one invocation of SelectPrompt.

WHAT is this pull request doing?

By checking for the condition before calling SelectPrompt, a friendly error message can be raised.

HOW to test your changes?

With a new user account that has no stores associated with it, attempt to link a store to a hydrogen project.

node [/path/to/shopify-cli]/packages/cli/bin/run.js hydrogen link
Before this change
$ node ./shopify-cli/packages/cli/bin/run.js hydrogen link

╭─ info ───────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  Release notes for 3.93.0                                                    │
│                                                                              │
│  Release highlights:                                                         │
│                                                                              │
│    - [App] Add app config validate command with --json support               │
│    - [App] Allow non-interactive app init                                    │
│    - [App] Deprecate --force on app deploy and app release                   │
│    - [App] Improve import scanning performance on app dev                    │
│    - [Theme] Allow --development flag to create a new theme                  │
│    - [Theme] Add JSON flag to theme preview                                  │
│                                                                              │
│  Read the complete release notes                                             │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯


  ERROR  SelectPrompt requires at least one choice

 file:///path/to/shopify-cli/packages/cli-kit/dist/private/node/ui/components/SelectPro
 mpt.js:8:15

 -SelectPromp (file:///path/to/shopify-cli/packages/cli-kit/dist/private/node/ui/compon
             ents/SelectPrompt.js:8:15)
 -Object.react_stack_bott (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.3
  m_frame                3.0_react@19.2.4/node_modules/react-reconciler/cjs/react-reconciler.developme
                         nt.js:17596:20)
 -renderWithHoo (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@
  s            19.2.4/node_modules/react-reconciler/cjs/react-reconciler.development.js:5335:22)
 -updateFunctionCompo (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_
  ent                react@19.2.4/node_modules/react-reconciler/cjs/react-reconciler.development.js:77
                     20:19)
 -beginWor (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.
          4/node_modules/react-reconciler/cjs/react-reconciler.development.js:9277:18)
 -runWithFiberIn (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react
  EV            @19.2.4/node_modules/react-reconciler/cjs/react-reconciler.development.js:2505:30)
 -performUnitOfW (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react
  rk            @19.2.4/node_modules/react-reconciler/cjs/react-reconciler.development.js:15273:22)
 -workLoopSyn (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19
             .2.4/node_modules/react-reconciler/cjs/react-reconciler.development.js:15099:41)
 -renderRootSy (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@1
  c           9.2.4/node_modules/react-reconciler/cjs/react-reconciler.development.js:15080:11)
 -performWorkOnR (/path/to/shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react
  ot            @19.2.4/node_modules/react-reconciler/cjs/react-reconciler.development.js:14245:35)

╭─ error ──────────────────────────────────────────────────────────────────────╮
│                                                                              │
│  SelectPrompt requires at least one choice                                   │
│                                                                              │
│  To investigate the issue, examine this stack trace:                         │
│    at SelectPrompt                                                           │
│    (cli-kit/src/private/node/ui/components/SelectPrompt.tsx:33)              │
│      throw new Error('SelectPrompt requires at least one choice')            │
│    at react_stack_bottom_frame                                               │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:17596)  │
│      return Component(props, secondArg);                                     │
│    at renderWithHooks                                                        │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:5335)   │
│      var children = callComponentInDEV(Component, props, secondArg);         │
│    at updateFunctionComponent                                                │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:7720)   │
│      Component = renderWithHooks(                                            │
│    at beginWork                                                              │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:9277)   │
│      return updateFunctionComponent(                                         │
│    at runWithFiberInDEV                                                      │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:2505)   │
│      ? fiber._debugTask.run(                                                 │
│    at performUnitOfWork                                                      │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:15273)  │
│      (current = runWithFiberInDEV(                                           │
│    at workLoopSync                                                           │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:15099)  │
│      for (; null !== workInProgress; ) performUnitOfWork(workInProgress);    │
│    at renderRootSync                                                         │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:15080)  │
│      workLoopSync();                                                         │
│    at performWorkOnRoot                                                      │
│    (../shopify-cli/node_modules/.pnpm/react-reconciler@0.33.0_react@19.2.4/  │
│    node_modules/react-reconciler/cjs/react-reconciler.development.js:14245)  │
│      errorRetryLanes = renderRootSync(                                       │
│                                                                              │
╰──────────────────────────────────────────────────────────────────────────────╯
After this change
$ node /path/to/shopify-cli/packages/cli/bin/run.js hydrogen link

To run this command, log in to Shopify.
User verification code: NCZB-TFMN
👉 Press any key to open the login page on your browser
Opened link to start the auth process: https://accounts.shopify.com/activate-with-code?device_code%5Buser_code%5D=NCZB-TFMN
✔ Logged in.
╭─ error ────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                            │
│  No shops found for your Shopify account.                                                                  │
│                                                                                                            │
│  If you're just getting started, create a free dev store in your Shopify Dev Dashboard, then run the       │
│  command again.                                                                                            │
│                                                                                                            │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

$ node /path/to/shopify-cli/packages/cli/bin/run.js hydrogen link
╭─ error ────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                            │
│  No shops found for your Shopify account.                                                                  │
│                                                                                                            │
│  If you're just getting started, create a free dev store in your Shopify Dev Dashboard, then run the       │
│  command again.                                                                                            │
│                                                                                                            │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or functional changes. Test changes or internal-only config changes do not require a changeset.
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copilot AI review requested due to automatic review settings April 10, 2026 20:29
@sealocal sealocal requested a review from a team as a code owner April 10, 2026 20:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents hydrogen link (and other flows calling login) from crashing with “SelectPrompt requires at least one choice” by detecting when the authenticated account has zero shops to select and surfacing a friendly AbortError instead.

Changes:

  • Add a guard in login() to abort early when userAccount.activeShops is empty, with a user-friendly message.
  • Add a unit test to ensure the empty-shops case throws and does not invoke renderSelectPrompt.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/cli/src/lib/auth.ts Adds an early AbortError when there are no shops to present to the select prompt.
packages/cli/src/lib/auth.test.ts Adds coverage for the no-active-shops scenario and ensures the select prompt is not called.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if (!preselected && userAccount.activeShops.length === 0) {
throw new AbortError(
'No shops found for your Shopify account.',
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userAccount.activeShops is filtered to only status === 'ACTIVE' in getUserAccount, so the error headline could be misleading if the account has shops but none are active. Consider wording this as “No active shops found for your Shopify account.” (or similar) to match the actual condition being checked.

Suggested change
'No shops found for your Shopify account.',
'No active shops found for your Shopify account.',

Copilot uses AI. Check for mistakes.
shop &&
userAccount.activeShops.find(({fqdn}) => shop === fqdn);

if (!preselected && userAccount.activeShops.length === 0) {
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !preselected && part of this condition is redundant because preselected can only be truthy when activeShops.length > 0. Simplifying to just if (userAccount.activeShops.length === 0) would make the intent clearer.

Suggested change
if (!preselected && userAccount.activeShops.length === 0) {
if (userAccount.activeShops.length === 0) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error "SelectPrompt requires at least one choice" when try to connect to storefront

2 participants